package com.sanhe.a448.activity.work;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.sanhe.a448.databinding.ActivityModeBinding;
import com.sanhe.a448.event.Event;
import com.sanhe.a448.utils.Const;
import com.sanhe.a448.utils.PortPipe;

public class ModeActivity extends BaseWorkActivity {

    ActivityModeBinding binding;
    public static int mode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityModeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.back.setOnClickListener(v -> finish());
        binding.setting.setOnClickListener(v -> Const.sendTouchEvent(0x83, 0x10, 0xc, 1, 0x1c));
        binding.cet.setOnClickListener(v -> {
            PortPipe.getInstance().goBack(new Runnable() {
                @Override
                public void run() {
                    mode = 1;
                    Const.sendTouchEvent(0x83, 0x10, 0xb, 1, 0xb);
                    jump();
                }
            });
        });
        binding.ret.setOnClickListener(v -> {
            PortPipe.getInstance().goBack(new Runnable() {
                @Override
                public void run() {
                    mode = 2;
                    Const.sendTouchEvent(0x83, 0x10, 0xb, 1, 0xa);
                    jump();
                }
            });
        });
        binding.hsp.setOnClickListener(v -> {
            PortPipe.getInstance().goBack(new Runnable() {
                @Override
                public void run() {
                    mode = 3;
                    Const.sendTouchEvent(0x83, 0x10, 0xb, 1, 0xc);
                    jump();
                }
            });
        });
        binding.four.setOnClickListener(v -> {
            PortPipe.getInstance().goBack(new Runnable() {
                @Override
                public void run() {
                    mode = 4;
                    Const.sendTouchEvent(0x83, 0x10, 0xb, 1, 0xd);
                    jump();
                }
            });
        });
        binding.view.setOnClickListener(v -> Const.sendTouchEvent(0x83, 0x10, 0xd, 0xb, 0xd));

        binding.back2.setOnClickListener(v -> {
            Const.sendTouchEvent(0x83, 0x1e, 1, 1, 0xa);
        });
    }

    private void jump() {
        if (!Const.jump) {
            return;
        }
        switch (mode) {
            case 1:
                Event.mode.postValue(2);
                break;
            case 2:
                Event.mode.postValue(1);
                break;
            case 3:
                Event.mode.postValue(3);
                break;
            case 4:
                Event.mode.postValue(4);
                break;
        }
        Event.stateSurface.postValue(4);
        Event.stateDeep.postValue(4);
        Event.start.postValue(4);
        Intent i = new Intent(this, WorkActivity.class);
        startActivity(i);
    }
}
